package cn.xiongxf.web.controller;

import cn.xiongxf.dto.SmsDto;
import cn.xiongxf.result.JsonResult;
import cn.xiongxf.service.IVerifyCodeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 获取图片验证码
     * @param key
     * @return
     */
    @GetMapping("/imageCode/{key}")
    @ApiOperation(value = "获取图片验证码的接口")
    public JsonResult imageVerifyCode(@PathVariable("key") String key){
        String base64Str = verifyCodeService.imageVerifyCode(key);
        return JsonResult.success(base64Str);
    }

    /**
     * 获取短信验证码
     * @param smsDto
     * @return
     */
    @RequestMapping("/sendSmsCode")
    public JsonResult sendSmsCode(@RequestBody @Valid SmsDto smsDto){
        verifyCodeService.sendSmsCode(smsDto);
        return JsonResult.success();
    }
}
